#pragma once

#ifdef WGLENGINE_DLL
#define WGLENGINE_EXPORT __declspec(dllexport)
#else
#define WGLENGINE_EXPORT __declspec(dllimport)
#endif


#include "GL\glew.h"
#include "glm\glm.hpp"
#include "WObject.h"

#include <memory>

class DirectionalLight;
class Shader;
class WGLENGINE_EXPORT ShadowMap : public WObject
{
protected:
	GLuint fbo;
	GLuint shadowMap;

	glm::mat4 VPMatrix;
	glm::mat4 orthoMatrix;
	glm::mat4 viewMatrix;
	glm::mat4 biasMatrix;

	std::shared_ptr<DirectionalLight> light;
	
	std::shared_ptr<Shader> shader;

public:
	ShadowMap();
	~ShadowMap();

	bool Init(int windowWidth, int windowHeight, std::shared_ptr<DirectionalLight> light);

	glm::mat4 GetVPMatrix()
	{
		return VPMatrix;
	}

	glm::mat4 GetViewMatrix()
	{
		return viewMatrix;
	}

	glm::mat4 GetProjectionMatrix()
	{
		return orthoMatrix;
	}

	glm::mat4 GetBiasMatrix()
	{
		return biasMatrix;
	}

	GLuint GetTextureID()
	{
		return shadowMap;
	}

	virtual void PreUpdate() override;

	void Bind();
	void Unbind();
};